﻿using AutoMapper;
using Org.BouncyCastle.Crypto;
using PublicModelsAndEntities.Models.UserAndRole;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XinjeMesProgram.Entities.Maintenance;
using XinjeMesProgram.Entities.RoleAndUser;

namespace XinjeMesProgram.Entities.Function
{
    /// <summary>
    /// 数据自动映射功能.
    /// </summary>
    public class MyDataAutoMapper
    {
        static MyDataAutoMapper()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile<SourceProfile>();
            });

            Mapper = config.CreateMapper();
        }

        /// <summary>
        /// Gets 映射器.
        /// </summary>
        public static IMapper Mapper { get; }

        /// <summary>
        /// 资源概括类.
        /// </summary>
        public class SourceProfile : Profile
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="SourceProfile"/> class.
            /// </summary>
            public SourceProfile()
            {
                this.CreateMap<MainsortRecordModel, RepairProductModel>()
                    .ForMember(d => d.ProductId, s => s.MapFrom(x => x.ID));
                this.CreateMap<MainsortRecordModel, MaintenanceCostModel>()
                    .ForMember(d => d.ID, s => s.MapFrom(x => x.ID));
            }
        }
    }
}
